package code.android.MiracleWalker.activity;

import code.android.MiracleWalker.R;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.widget.Toast;

public class MwPreferenceActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {

	Preference mPreference;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.layout.preference);
		mPreference = (Preference) getPreferenceScreen().findPreference("checkbox_preference");
	}
	
	@Override
	protected void onResume() {
		getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener( this );
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( this );
		super.onPause();
	}
	
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {	

		if(key.equals("checkbox_preference")) {
			Toast.makeText(this, "KEY:" + key + "\ngetBoolean():" + sharedPreferences.getBoolean(key, false), Toast.LENGTH_SHORT).show();
		}
		
	}

}
